import os
import cv2



dirtype = ("train", "label", "test")
strpwd = os.getcwd()
print("pwd = %s" % strpwd)


loadDir = r"H:\data\XH_0111\sort"
saveDir = r"H:\data\XH_0111\equ"

# loadDir = r"F:\samples\hongzao2000\zao\2000\2000"
# saveDir = r"F:\samples\hongzao2000\zao\2000\change_name"
dirNames = os.listdir(loadDir)
print(dirNames)

for i in range(0,len(dirNames)):
    dirPath = os.path.join(loadDir, dirNames[i])
    save_path = os.path.join(saveDir, dirNames[i])
    if not os.path.exists(save_path):
        os.mkdir(save_path)
    imgNames = os.listdir(dirPath)
    # print(imgNames)
    for j in range(0, len(imgNames)):
        title = imgNames[j].split(".")[0]
        idx = title.split("_")[-1]
        idx_i = int(idx)
        imgPath = os.path.join(dirPath, imgNames[j])
        # im = cv2.imread(imgPath)
        img = cv2.imread(imgPath, 1)
        cv2.imshow("ori", cv2.resize(img, (600, 600)))
        img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
        cv2.equalizeHist(img, img)
        writePath = os.path.join(save_path, imgNames[j])
        print(writePath)
        cv2.imwrite(writePath, img)
        font = cv2.FONT_HERSHEY_SIMPLEX
        imgzi = cv2.putText(img, imgNames[j], (50, 30), font, 1.2, (255, 255, 255), 2)
        cv2.imshow("equ", cv2.resize(img, (600,600)))
        cv2.waitKey(1000)
